package ejb.cbm.operatoria.session;

import java.util.List;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import ejb.cbm.operatoria.entity.OperacionConsultaSaldoEntity;
import ejb.cbm.operatoria.local.OperacionConsultaSaldoSessionLocal;

////@Stateless
public class OperacionConsultaSaldoSession extends HibernateDaoSupport implements OperacionConsultaSaldoSessionLocal {
	
	static Logger logger = Logger.getLogger(OperacionConsultaSaldoSession.class.getName());
	
	//property constants
	public static final String CODIGODIVISA = "codigodivisa";
	public static final String SALDODISPONIBLE = "saldodisponible";
	public static final String SALDOACTUAL = "saldoactual";
	public static final String ESTADOIMPRESION = "estadoimpresion";
	public static final String USUARIOREGISTRO = "usuarioregistro";
	public static final String USUARIOMODIFICACION = "usuariomodificacion";


    ////@PersistenceContext
    //private EntityManager entityManager;
	
	@Autowired
	public OperacionConsultaSaldoSession(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}
	
    public void save(OperacionConsultaSaldoEntity transientInstance) {
    	logger.log("saving OperacionConsultaSaldoEntity instance", Level.INFO, null,null);
        try {
            getSession().persist(transientInstance);
            logger.log("save successful", Level.INFO, null,null);
        } catch (RuntimeException re) {
        	logger.log("save failed", Level.FATAL,null, re);
            throw re;
        }
    }
    
    public void delete(OperacionConsultaSaldoEntity persistentInstance) {
    	logger.log("deleting OperacionConsultaSaldoEntity instance", Level.INFO, null,null);
        try {
            getSession().delete(persistentInstance);
            logger.log("delete successful", Level.INFO, null,null);
        } catch (RuntimeException re) {
        	logger.log("delete failed", Level.FATAL,null, re);
            throw re;
        }
    }
    
    public OperacionConsultaSaldoEntity update(OperacionConsultaSaldoEntity detachedInstance) {
    	logger.log("updating OperacionConsultaSaldoEntity instance", Level.INFO, null,null);
        try {
            OperacionConsultaSaldoEntity result = (OperacionConsultaSaldoEntity) getSession().merge(detachedInstance);
            logger.log("update successful", Level.INFO, null,null);
            return result;
        } catch (RuntimeException re) {
        	logger.log("update failed", Level.FATAL,null, re);
            throw re;
        }
    }
    
    public OperacionConsultaSaldoEntity findById( Long id) {
    	logger.log("finding OperacionConsultaSaldoEntity instance with id: " + id, Level.INFO, null,null);
        try {
            OperacionConsultaSaldoEntity instance = (OperacionConsultaSaldoEntity) getSession().get(OperacionConsultaSaldoEntity.class, id);
            return instance;
        } catch (RuntimeException re) {
        	logger.log("find failed", Level.FATAL,null, re);
            throw re;
        }
    }
    
    //@SuppressWarnings("unchecked")
    public List<OperacionConsultaSaldoEntity> findByProperty(String propertyName, Object value) {
    	logger.log("finding OperacionConsultaSaldoEntity instance with property: " + propertyName
    						+ ", value: " + value, Level.INFO, null,null);
		try {
			String queryString = "select model from OperacionConsultaSaldoEntity model where model." 
			 						+ propertyName + "= :propertyValue";
			return getSession().createQuery(queryString)
 				.setParameter("propertyValue", value).list();
		} catch (RuntimeException re) {
			logger.log("find by property name failed", Level.FATAL,null, re);
			throw re;
		}
	}
	
	public List<OperacionConsultaSaldoEntity> findByCodigodivisa(Object codigodivisa) {
		return findByProperty(CODIGODIVISA, codigodivisa);
	}
	
	public List<OperacionConsultaSaldoEntity> findBySaldodisponible(Object saldodisponible) {
		return findByProperty(SALDODISPONIBLE, saldodisponible);
	}
	
	public List<OperacionConsultaSaldoEntity> findBySaldoactual(Object saldoactual) {
		return findByProperty(SALDOACTUAL, saldoactual);
	}
	
	public List<OperacionConsultaSaldoEntity> findByEstadoimpresion(Object estadoimpresion) {
		return findByProperty(ESTADOIMPRESION, estadoimpresion);
	}
	
	public List<OperacionConsultaSaldoEntity> findByUsuarioregistro(Object usuarioregistro) {
		return findByProperty(USUARIOREGISTRO, usuarioregistro);
	}
	
	public List<OperacionConsultaSaldoEntity> findByUsuariomodificacion(Object usuariomodificacion) {
		return findByProperty(USUARIOMODIFICACION, usuariomodificacion);
	}
	

	//@SuppressWarnings("unchecked")
	public List<OperacionConsultaSaldoEntity> findAll() {
		logger.log("finding all OperacionConsultaSaldoEntity instances", Level.INFO, null,null);
		try {
			String queryString = "select model from OperacionConsultaSaldoEntity model";
			return getSession().createQuery(queryString).list();
		} catch (RuntimeException re) {
			logger.log("find all failed", Level.FATAL,null, re);
			throw re;
		}
	}
}